﻿using System;
using System.Numerics;
using Me.Prettyprint.Hector.Api.Beans;
using Me.Prettyprint.Hector.Api.Ddl;

namespace Me.Prettyprint.Cassandra.Serializers
{
    public class SerializerTypeInferer
    {
        public static Me.Prettyprint.Hector.Api.Serializer<T> GetSerializer<T>(object value)
        {
            Me.Prettyprint.Hector.Api.Serializer<T> serializer = null;
            if (value is BigInteger)
            {
                serializer = (Me.Prettyprint.Hector.Api.Serializer<T>)BigIntegerSerializer.Instance;
            }
            else if (value is bool)
            {
                serializer = (Me.Prettyprint.Hector.Api.Serializer<T>)BooleanSerializer.Instance;
            }
            else if (value is byte[])
            {
                serializer = (Me.Prettyprint.Hector.Api.Serializer<T>)BytesArraySerializer.Instance;
            }
            else if (value is Char)
            {
                serializer = (Me.Prettyprint.Hector.Api.Serializer<T>)CharSerializer.Instance;
            }
            else if (value is Composite)
            {
                serializer = (Me.Prettyprint.Hector.Api.Serializer<T>)CompositeSerializer.Instance;
            }
            else if (value is DynamicComposite)
            {
                serializer = (Me.Prettyprint.Hector.Api.Serializer<T>)DynamicCompositeSerializer.Instance;
            }
            else if (value is DateTime)
            {
                serializer = (Me.Prettyprint.Hector.Api.Serializer<T>)DateSerializer.Instance;
            }
            else if (value is double)
            {
                serializer = (Me.Prettyprint.Hector.Api.Serializer<T>)DoubleSerializer.Instance;
            }
            else if (value is float)
            {
                serializer = (Me.Prettyprint.Hector.Api.Serializer<T>)FloatSerializer.Instance;
            }
            else if (value is int)
            {
                serializer = (Me.Prettyprint.Hector.Api.Serializer<T>)IntegerSerializer.Instance;
            }
            else if (value is long)
            {
                serializer = (Me.Prettyprint.Hector.Api.Serializer<T>)LongSerializer.Instance;
            }
            else if (value is short)
            {
                serializer = (Me.Prettyprint.Hector.Api.Serializer<T>)ShortSerializer.Instance;
            }
            else if (value is string || value is System.String)
            {
                serializer = (Me.Prettyprint.Hector.Api.Serializer<T>)StringSerializer.Instance;
            }
            else if (value is Guid)
            {
                serializer = (Me.Prettyprint.Hector.Api.Serializer<T>)UUIDSerializer.Instance;
            }
            else
            {
                serializer = (Me.Prettyprint.Hector.Api.Serializer<T>)ObjectSerializer.Instance;
            }
            return serializer;
        }
    }
}
